//
//  LoginViewController.m
//  QuickCure
//
//  Created by 马文星 on 16/4/28.
//  Copyright © 2016年 Demos. All rights reserved.
//

#import "LoginViewController.h"
#import "UserDTO.h"

@interface LoginViewController ()

/** 账户 */
@property (weak, nonatomic) IBOutlet UITextField *accountTextField;

/** 密码 */
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;


@end



@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];


}


- (IBAction)login:(id)sender {
    
    
    if (self.accountTextField.text.length==0) {
        
        [SVPAlertManager alertErrorStatus:@"请输入账户"];
        return;
    }
    if (self.passwordTextField.text.length==0) {
        
        [SVPAlertManager alertErrorStatus:@"请输入账户"];
        return;
    }
    
    if (![self.passwordTextField.text isEqualToString:@"11"]|| ![self.passwordTextField.text isEqualToString:@"11"]) {
        
        [SVPAlertManager alertErrorStatus:@"请输入正确的账户或者密码"];
        return;
    }
    
    if ([self.passwordTextField.text isEqualToString:@"11"]&& [self.passwordTextField.text isEqualToString:@"11"]) {
        

        if ([NetWorkTool shareManager].isReachableByAFN) {
            
            WEAKSELF
            [[NetWorkManager sharedManager] loginWithLoadUserInfo:^(UserDTO *dto) {
                
                //登录成功
                [MLDefaults setBool:YES forKey:kIsUserLoginKey];
                
                //保存数据
                [[UserDTO sharedInstance] saveUserInfoToSanbox:dto];
                
                //回调处理
                weakSelf.loginBlock();
                
                [weakSelf goBack];
            }];
            
        }else{
            
            [SVPAlertManager alertErrorStatus:kNetWorkFailureStatus];
        }
 
    }
}


-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    [self.view endEditing:YES];
}


@end
